package com.example.aboutreview;

import org.junit.Test;

public class ReflectionCase {

    @Test
    public void 性能测试() throws Exception {
        //随着次数的增加 会减少用时 但是反射依旧不如
        doRegular();
        doReflection();
    }

    public static void doRegular() throws Exception {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            A a = new A();
            a.doSomeThing();
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    public static void doReflection() throws Exception {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            A a = A.class.newInstance();
            a.doSomeThing();
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    static class A {


        public void doSomeThing() {
        }
    }

}
